﻿using IllustratedCsharp7_ch8_ExtendMyData;
using System;
using System.Collections.Generic;
using System.Text;
using static IllustratedCsharp7_ch8.MyData;

namespace IllustratedCsharp7_ch8
{
    class chapt7_14ExtensionMethod
    {
        static void _Main()
        {
            MyData md = new MyData(3,4,5);
            Console.WriteLine("Average:{0}", ExtendMyData.Average(md)); //静态调用形式

            Console.WriteLine($"Sum: {md.Sum()}");
           // Console.WriteLine("Average: {0}",md.Average());           //实例调用形式       
        }
    }
    public sealed class MyData
    {
        private double D1;              //字段
        private double D2;
        private double D3;

        public MyData(double d1, double d2, double d3)
        {
            D1 = d1; D2 = d2;D3 = d3;
        }
        public double Sum()
        {
            return D1 + D2 + D3;
        }
    }
}

